# python -m project_root.api.api_report
from .api_token import Token 
from util.time_util import timestran
import requests


class Api_Report(Token):


    def get_reportlist(self,start_time='',end_time='',type=''):
        url = 'http://hxzhan.rtcloud.com:32111/tm/report/list'
        json = {
            'dateRange': [timestran(start_time), timestran(end_time)], 
            'page': 1, 
            'limit': 10,
            }
        if start_time != '':
            json.update(start_time=start_time,end_time=end_time)
        if type != '':
            json.update(type = type)

        response = requests.post(url=url,json=json,headers=self.get_header())
        values = []
        keys = ['created_at','name','type']
        datalist = response.json()['data']['list']
        for data in datalist:
            for key in keys:
                if key == 'created_at':
                    values.append(timestran(data[key]))
                elif key == 'type':
                    if data[key] == 1:
                        values.append('周报')
                    elif data[key] == 2:
                        values.append('月报')
                    elif data[key] == 3:
                        values.append('季报')
                    elif data[key] == 4:
                        values.append('半年报')
                    elif data[key] == 5:
                        values.append('年报')
                else:
                    values.append(data[key])
        return values

       




# ap = Api_Report()
# print(ap.get_reportlist(type=5))
# # print(ap.get_reportlist())